package com.yanqu.road.server.manager.activity.horserun;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.logic.activity.horserun.HorseRunConfig;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.server.TempCrossMgr;
import com.yanqu.road.server.manager.activity.ActivityMgr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 小马快跑跨服配置管理类
 */
public class CrossHorseRunConfigMgr extends TempCrossMgr {

    private static Map<Integer, HorseRunConfig> configMap = new ConcurrentHashMap<>();

    @Override
    public boolean removeExpireData() throws Exception {
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    public static HorseRunConfig getHorseRunConfig(int activityId) {
        return configMap.get(activityId);
    }

    public static HorseRunConfig reloadHorseRunConfig(int activityId) {
        ActivityInfo activityInfo = ActivityMgr.getActivityInfoMayLoadDB(activityId);
        if (activityInfo == null) {
            return null;
        }
        if (activityInfo.getType() != eActivityType.HorseRun.getValue()){
            return null;
        }

        List<Integer> activityIdList = new ArrayList<>();
        activityIdList.add(activityId);
        Map<String, ActivityConfig> activityConfigMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(activityId);

        HorseRunConfig config = new HorseRunConfig(activityInfo,activityConfigMap);
        configMap.put(activityId, config);
        return config;
    }
}
